//
//  DoubleView.m
//  inrtest
//
//  Created by 宋辉 on 2017/4/21.
//  Copyright © 2017年 . All rights reserved.
//

#import "DoubleView.h"

@implementation DoubleView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        [self CreateView];
    }
    return self;
}

-(void)CreateView{
    
    // 球号
    UICollectionViewFlowLayout *layOut = [[UICollectionViewFlowLayout alloc]init];
    _BallCollectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layOut];
    _BallCollectionView.allowsMultipleSelection = YES;
    _BallCollectionView.backgroundColor = [UIColor whiteColor];
    [self addSubview:_BallCollectionView];
    
    if(iPhoneX){
        
        [_BallCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_equalTo(ScreenHeigth-88-52-34);
            make.top.equalTo(self).with.offset(0);
            make.leading.equalTo(self).with.offset(0);
        }];
        
    }else{
        
        [_BallCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(ScreenWidth);
            make.height.mas_equalTo(ScreenHeigth-64-52);
            make.top.equalTo(self).with.offset(0);
            make.leading.equalTo(self).with.offset(0);
        }];
    }
    

    
    UIView *line2 = [[UIView alloc]init];
    line2.backgroundColor =DEF_COLOR_F0F0F0 ;
    [self addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.bottom.mas_equalTo(self.mas_bottom).offset(-52);
        make.size.mas_equalTo(CGSizeMake(SCREEN_SIZE.width, 1));
    }];
    
    
    UIImageView* clearImage=[UIImageView new];
    clearImage.image=[UIImage imageNamed:@"LJT_"];
    [self addSubview:clearImage];
    [clearImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(22);
        make.bottom.equalTo(self.mas_bottom).with.offset(-25);
        make.leading.equalTo(self).with.offset(12);
    }];
    
    
    UILabel* faxed=[UILabel new];
    faxed.text=@"清空";
    faxed.font=[UIFont systemFontOfSize:12];
    faxed.textColor=baseLightBlackColor;
    faxed.textAlignment=NSTextAlignmentCenter;
    [self addSubview:faxed];
    [faxed mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(12);
        make.top.equalTo(clearImage.mas_bottom).with.offset(5+3);
        make.leading.equalTo(self).with.offset(10);
    }];
    
    
    UIButton* clearBut=[UIButton new];
    [clearBut addTarget:self action:@selector(clearButClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:clearBut];
    [clearBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(51);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.leading.equalTo(self).with.offset(0);
    }];
    
    UIView* line3=[UIView new];
    line3.backgroundColor=DEF_COLOR_F0F0F0;
    [self addSubview:line3];
    [line3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(1);
        make.height.mas_equalTo(42);
        make.bottom.equalTo(self.mas_bottom).with.offset(-5);
        make.leading.equalTo(clearImage.mas_trailing).with.offset(15);
    }];
    
    UIImageView* shackImage=[UIImageView new];
    shackImage.image=[UIImage imageNamed:@"YYY_"];
    [self addSubview:shackImage];
    [shackImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(25);
        make.bottom.equalTo(self.mas_bottom).with.offset(-22);
        make.leading.equalTo(line3.mas_trailing).with.offset(15);
    }];
    
    UILabel* faxed2=[UILabel new];
    faxed2.text=@"摇号";
    faxed2.font=[UIFont systemFontOfSize:12];
    faxed2.textColor=baseLightBlackColor;
    faxed2.textAlignment=NSTextAlignmentCenter;
    [self addSubview:faxed2];
    [faxed2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(25);
        make.height.mas_equalTo(12);
        make.top.equalTo(shackImage.mas_bottom).with.offset(5);
        make.leading.equalTo(line3.mas_trailing).with.offset(11);
    }];
    
    UIButton* shackBut=[UIButton new];
    [shackBut addTarget:self action:@selector(shackButClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:shackBut];
    [shackBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(51);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.leading.equalTo(line3.mas_trailing).with.offset(0);
    }];
    
    UILabel* faxed3=[UILabel new];
    faxed3.text=@"摇一摇，机选一注";
    faxed3.font=[UIFont systemFontOfSize:14];
    faxed3.textColor=baseLightBlackColor;
    faxed3.textAlignment=NSTextAlignmentCenter;
    [self addSubview:faxed3];
    [faxed3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(14);
        make.bottom.equalTo(self.mas_bottom).with.offset(-18);
        make.leading.equalTo(faxed2.mas_trailing).with.offset(5);
    }];
    
    UIButton* sureBut=[UIButton new];
    [sureBut setTitle:@"确定" forState:UIControlStateNormal];
    sureBut.backgroundColor=DEF_COLOR_MAINCOLOR;
    [sureBut setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sureBut addTarget:self action:@selector(sureButClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:sureBut];
    [sureBut mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(52);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
        make.trailing.equalTo(self.mas_trailing).with.offset(0);
    }];
    
}

-(void)clearButClick{
    
    if ([self.delegate respondsToSelector:@selector(clearButClick)]) {
        [self.delegate clearButClick];
    }
    
}
-(void)shackButClick{
    
    if ([self.delegate respondsToSelector:@selector(shackButClick)]) {
        [self.delegate shackButClick];
    }
}

//确定
-(void)sureButClick{
    
    if ([self.delegate respondsToSelector:@selector(sureButClick)]) {
        [self.delegate sureButClick];
    }
    
}

@end
